#include "APP_KEY.h"
static void key_handle(int key_value)
{
    printf("key_value = %d\n", key_value);
    if (App_Display_Get_Page() == 2)
    {
        if (key_value == 1)
        {
            App_motor_Value_SetMaxSpeedPRM(App_motor_Value_GetMaxSpeedPRM() + 20);
           
        }
        else if (key_value == 2)
        {
            App_motor_Value_SetMaxSpeedPRM(App_motor_Value_GetMaxSpeedPRM() - 20);
            
        }
        else if (key_value == 3)
        {
              App_Motor_Start();
          
        }
        else if (key_value == 4)
        {
            App_Display_Change_Page();
           
        }
    }
    else if (App_Display_Get_Page() == 3)
    {

        if (key_value == 1)
        {
            App_ID_Save(App_ID_GetId() + 1);
            printf("Id = %d",App_ID_GetId());
            
        }
        else if (key_value == 2)
        {
            App_ID_Save(App_ID_GetId() - 1);
             printf("Id = %d",App_ID_GetId());
            
        }
        else if (key_value == 3)
        {
             App_Motor_Start();
           
        }
        else if (key_value == 4)
        {
            App_Display_Change_Page();
           
        }
    }
    else if (App_Display_Get_Page() == 1)
    {
        if (key_value == 1)
        {
            App_motor_Value_SetTargetAngel(App_motor_Value_GetTargetAngel() + 90);
          
        }
        else if (key_value == 2)
        {
            App_motor_Value_SetTargetAngel(App_motor_Value_GetTargetAngel() - 90);
           
        }

        else if (key_value == 3)
        {
             App_Motor_Start();
           
       
        }
        else if (key_value == 4)
        {
            App_Display_Change_Page();
            
        }
    }
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    printf("EXTI Callback: Pin %d\n", GPIO_Pin);

    if (GPIO_Pin == KEY1_Pin)
    {
        HAL_Delay(10);
        if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET)
        {
            printf("KEY1");
            key_handle(1);
        }
    }
    else if (GPIO_Pin == KEY2_Pin)
    {
        printf("KEY2");
        HAL_Delay(10);
        if (HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin) == GPIO_PIN_RESET)
        {
            key_handle(2);
        }
    }
    else if (GPIO_Pin == KEY3_Pin)
    {
        printf("KEY3");
        HAL_Delay(10);
        if (HAL_GPIO_ReadPin(KEY3_GPIO_Port, KEY3_Pin) == GPIO_PIN_RESET)
        {
            key_handle(3);
        }
    }
    else if (GPIO_Pin == KEY4_Pin)
    {
        printf("KEY4");
        HAL_Delay(10);
        if (HAL_GPIO_ReadPin(KEY4_GPIO_Port, KEY4_Pin) == GPIO_PIN_RESET)
        {
            key_handle(4);
        }
    }
}
